﻿#region Using directives

using System;
using System.Data;
using System.Data.Common;
using System.Collections;
using System.Collections.Generic;

using VCS.Entities;
using VCS.Data;

#endregion

namespace VCS.Data.Bases
{	
	///<summary>
	/// This class is the base class for any <see cref="PatientProviderBase"/> implementation.
	/// It exposes CRUD methods as well as selecting on index, foreign keys and custom stored procedures.
	///</summary>
	public abstract partial class PatientProviderBaseCore : EntityProviderBase<VCS.Entities.Patient, VCS.Entities.PatientKey>
	{		
		#region Get from Many To Many Relationship Functions
		#endregion	
		
		#region Delete Methods

		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to delete.</param>
		/// <returns>Returns true if operation suceeded.</returns>
		public override bool Delete(TransactionManager transactionManager, VCS.Entities.PatientKey key)
		{
			return Delete(transactionManager, key.PatientCode);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="_patientCode">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public bool Delete(System.String _patientCode)
		{
			return Delete(null, _patientCode);
		}
		
		/// <summary>
		/// 	Deletes a row from the DataSource.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_patientCode">. Primary Key.</param>
		/// <remarks>Deletes based on primary key(s).</remarks>
		/// <returns>Returns true if operation suceeded.</returns>
		public abstract bool Delete(TransactionManager transactionManager, System.String _patientCode);		
		
		#endregion Delete Methods
		
		#region Get By Foreign Key Functions
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		FK_Patient_Company Description: 
		/// </summary>
		/// <param name="_companyCode"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByCompanyCode(System.String _companyCode)
		{
			int count = -1;
			return GetByCompanyCode(_companyCode, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		FK_Patient_Company Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyCode"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		/// <remarks></remarks>
		public TList<Patient> GetByCompanyCode(TransactionManager transactionManager, System.String _companyCode)
		{
			int count = -1;
			return GetByCompanyCode(transactionManager, _companyCode, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		FK_Patient_Company Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByCompanyCode(TransactionManager transactionManager, System.String _companyCode, int start, int pageLength)
		{
			int count = -1;
			return GetByCompanyCode(transactionManager, _companyCode, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		fkPatientCompany Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyCode"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByCompanyCode(System.String _companyCode, int start, int pageLength)
		{
			int count =  -1;
			return GetByCompanyCode(null, _companyCode, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		fkPatientCompany Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_companyCode"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByCompanyCode(System.String _companyCode, int start, int pageLength,out int count)
		{
			return GetByCompanyCode(null, _companyCode, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Company key.
		///		FK_Patient_Company Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_companyCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public abstract TList<Patient> GetByCompanyCode(TransactionManager transactionManager, System.String _companyCode, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		FK_Patient_Country Description: 
		/// </summary>
		/// <param name="_nationality"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByNationality(System.String _nationality)
		{
			int count = -1;
			return GetByNationality(_nationality, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		FK_Patient_Country Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nationality"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		/// <remarks></remarks>
		public TList<Patient> GetByNationality(TransactionManager transactionManager, System.String _nationality)
		{
			int count = -1;
			return GetByNationality(transactionManager, _nationality, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		FK_Patient_Country Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nationality"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByNationality(TransactionManager transactionManager, System.String _nationality, int start, int pageLength)
		{
			int count = -1;
			return GetByNationality(transactionManager, _nationality, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		fkPatientCountry Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_nationality"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByNationality(System.String _nationality, int start, int pageLength)
		{
			int count =  -1;
			return GetByNationality(null, _nationality, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		fkPatientCountry Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_nationality"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByNationality(System.String _nationality, int start, int pageLength,out int count)
		{
			return GetByNationality(null, _nationality, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country key.
		///		FK_Patient_Country Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_nationality"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public abstract TList<Patient> GetByNationality(TransactionManager transactionManager, System.String _nationality, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		FK_Patient_Country1 Description: 
		/// </summary>
		/// <param name="_homeCountry"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByHomeCountry(System.String _homeCountry)
		{
			int count = -1;
			return GetByHomeCountry(_homeCountry, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		FK_Patient_Country1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_homeCountry"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		/// <remarks></remarks>
		public TList<Patient> GetByHomeCountry(TransactionManager transactionManager, System.String _homeCountry)
		{
			int count = -1;
			return GetByHomeCountry(transactionManager, _homeCountry, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		FK_Patient_Country1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_homeCountry"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByHomeCountry(TransactionManager transactionManager, System.String _homeCountry, int start, int pageLength)
		{
			int count = -1;
			return GetByHomeCountry(transactionManager, _homeCountry, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		fkPatientCountry1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_homeCountry"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByHomeCountry(System.String _homeCountry, int start, int pageLength)
		{
			int count =  -1;
			return GetByHomeCountry(null, _homeCountry, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		fkPatientCountry1 Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_homeCountry"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByHomeCountry(System.String _homeCountry, int start, int pageLength,out int count)
		{
			return GetByHomeCountry(null, _homeCountry, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_Country1 key.
		///		FK_Patient_Country1 Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_homeCountry"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public abstract TList<Patient> GetByHomeCountry(TransactionManager transactionManager, System.String _homeCountry, int start, int pageLength, out int count);
		
	
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		FK_Patient_MemberType Description: 
		/// </summary>
		/// <param name="_memberType"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByMemberType(System.String _memberType)
		{
			int count = -1;
			return GetByMemberType(_memberType, 0,int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		FK_Patient_MemberType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_memberType"></param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		/// <remarks></remarks>
		public TList<Patient> GetByMemberType(TransactionManager transactionManager, System.String _memberType)
		{
			int count = -1;
			return GetByMemberType(transactionManager, _memberType, 0, int.MaxValue, out count);
		}
		
			/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		FK_Patient_MemberType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_memberType"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		///  <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByMemberType(TransactionManager transactionManager, System.String _memberType, int start, int pageLength)
		{
			int count = -1;
			return GetByMemberType(transactionManager, _memberType, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		fkPatientMemberType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_memberType"></param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByMemberType(System.String _memberType, int start, int pageLength)
		{
			int count =  -1;
			return GetByMemberType(null, _memberType, start, pageLength,out count);	
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		fkPatientMemberType Description: 
		/// </summary>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="_memberType"></param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public TList<Patient> GetByMemberType(System.String _memberType, int start, int pageLength,out int count)
		{
			return GetByMemberType(null, _memberType, start, pageLength, out count);	
		}
						
		/// <summary>
		/// 	Gets rows from the datasource based on the FK_Patient_MemberType key.
		///		FK_Patient_MemberType Description: 
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_memberType"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns a typed collection of VCS.Entities.Patient objects.</returns>
		public abstract TList<Patient> GetByMemberType(TransactionManager transactionManager, System.String _memberType, int start, int pageLength, out int count);
		
		#endregion

		#region Get By Index Functions
		
		/// <summary>
		/// 	Gets a row from the DataSource based on its primary key.
		/// </summary>
		/// <param name="transactionManager">A <see cref="TransactionManager"/> object.</param>
		/// <param name="key">The unique identifier of the row to retrieve.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <returns>Returns an instance of the Entity class.</returns>
		public override VCS.Entities.Patient Get(TransactionManager transactionManager, VCS.Entities.PatientKey key, int start, int pageLength)
		{
			return GetByPatientCode(transactionManager, key.PatientCode, start, pageLength);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByFirstNameLastNameIsDisabled(System.String _firstName, System.String _lastName, System.Boolean _isDisabled)
		{
			int count = -1;
			return GetByFirstNameLastNameIsDisabled(null,_firstName, _lastName, _isDisabled, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByFirstNameLastNameIsDisabled(System.String _firstName, System.String _lastName, System.Boolean _isDisabled, int start, int pageLength)
		{
			int count = -1;
			return GetByFirstNameLastNameIsDisabled(null, _firstName, _lastName, _isDisabled, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByFirstNameLastNameIsDisabled(TransactionManager transactionManager, System.String _firstName, System.String _lastName, System.Boolean _isDisabled)
		{
			int count = -1;
			return GetByFirstNameLastNameIsDisabled(transactionManager, _firstName, _lastName, _isDisabled, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByFirstNameLastNameIsDisabled(TransactionManager transactionManager, System.String _firstName, System.String _lastName, System.Boolean _isDisabled, int start, int pageLength)
		{
			int count = -1;
			return GetByFirstNameLastNameIsDisabled(transactionManager, _firstName, _lastName, _isDisabled, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByFirstNameLastNameIsDisabled(System.String _firstName, System.String _lastName, System.Boolean _isDisabled, int start, int pageLength, out int count)
		{
			return GetByFirstNameLastNameIsDisabled(null, _firstName, _lastName, _isDisabled, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_FirstNameLastNameIsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_firstName"></param>
		/// <param name="_lastName"></param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public abstract TList<Patient> GetByFirstNameLastNameIsDisabled(TransactionManager transactionManager, System.String _firstName, System.String _lastName, System.Boolean _isDisabled, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key IX_IsActive index.
		/// </summary>
		/// <param name="_isDisabled"></param>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByIsDisabled(System.Boolean _isDisabled)
		{
			int count = -1;
			return GetByIsDisabled(null,_isDisabled, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_IsActive index.
		/// </summary>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByIsDisabled(System.Boolean _isDisabled, int start, int pageLength)
		{
			int count = -1;
			return GetByIsDisabled(null, _isDisabled, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_IsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_isDisabled"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByIsDisabled(TransactionManager transactionManager, System.Boolean _isDisabled)
		{
			int count = -1;
			return GetByIsDisabled(transactionManager, _isDisabled, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_IsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByIsDisabled(TransactionManager transactionManager, System.Boolean _isDisabled, int start, int pageLength)
		{
			int count = -1;
			return GetByIsDisabled(transactionManager, _isDisabled, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_IsActive index.
		/// </summary>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public TList<Patient> GetByIsDisabled(System.Boolean _isDisabled, int start, int pageLength, out int count)
		{
			return GetByIsDisabled(null, _isDisabled, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the IX_IsActive index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_isDisabled"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="TList&lt;Patient&gt;"/> class.</returns>
		public abstract TList<Patient> GetByIsDisabled(TransactionManager transactionManager, System.Boolean _isDisabled, int start, int pageLength, out int count);
						
		/// <summary>
		/// 	Gets rows from the datasource based on the primary key PK_Patient index.
		/// </summary>
		/// <param name="_patientCode"></param>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public VCS.Entities.Patient GetByPatientCode(System.String _patientCode)
		{
			int count = -1;
			return GetByPatientCode(null,_patientCode, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Patient index.
		/// </summary>
		/// <param name="_patientCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public VCS.Entities.Patient GetByPatientCode(System.String _patientCode, int start, int pageLength)
		{
			int count = -1;
			return GetByPatientCode(null, _patientCode, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Patient index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_patientCode"></param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public VCS.Entities.Patient GetByPatientCode(TransactionManager transactionManager, System.String _patientCode)
		{
			int count = -1;
			return GetByPatientCode(transactionManager, _patientCode, 0, int.MaxValue, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Patient index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_patientCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public VCS.Entities.Patient GetByPatientCode(TransactionManager transactionManager, System.String _patientCode, int start, int pageLength)
		{
			int count = -1;
			return GetByPatientCode(transactionManager, _patientCode, start, pageLength, out count);
		}
		
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Patient index.
		/// </summary>
		/// <param name="_patientCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">out parameter to get total records for query</param>
		/// <remarks></remarks>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public VCS.Entities.Patient GetByPatientCode(System.String _patientCode, int start, int pageLength, out int count)
		{
			return GetByPatientCode(null, _patientCode, start, pageLength, out count);
		}
		
				
		/// <summary>
		/// 	Gets rows from the datasource based on the PK_Patient index.
		/// </summary>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="_patientCode"></param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="count">The total number of records.</param>
		/// <returns>Returns an instance of the <see cref="VCS.Entities.Patient"/> class.</returns>
		public abstract VCS.Entities.Patient GetByPatientCode(TransactionManager transactionManager, System.String _patientCode, int start, int pageLength, out int count);
						
		#endregion "Get By Index Functions"
	
		#region Custom Methods
		
		
		#region _Patient_GetPatientCode 
		
		/// <summary>
		///	This method wrap the '_Patient_GetPatientCode' stored procedure. 
		/// </summary>
		/// <param name="locationCode"> A <c>System.String</c> instance.</param>
		/// <param name="lastName"> A <c>System.String</c> instance.</param>
			/// <param name="patientCode"> A <c>System.String</c> instance.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void GetPatientCode(System.String locationCode, System.String lastName, ref System.String patientCode)
		{
			 GetPatientCode(null, 0, int.MaxValue , locationCode, lastName, ref patientCode);
		}
		
		/// <summary>
		///	This method wrap the '_Patient_GetPatientCode' stored procedure. 
		/// </summary>
		/// <param name="locationCode"> A <c>System.String</c> instance.</param>
		/// <param name="lastName"> A <c>System.String</c> instance.</param>
			/// <param name="patientCode"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void GetPatientCode(int start, int pageLength, System.String locationCode, System.String lastName, ref System.String patientCode)
		{
			 GetPatientCode(null, start, pageLength , locationCode, lastName, ref patientCode);
		}
				
		/// <summary>
		///	This method wrap the '_Patient_GetPatientCode' stored procedure. 
		/// </summary>
		/// <param name="locationCode"> A <c>System.String</c> instance.</param>
		/// <param name="lastName"> A <c>System.String</c> instance.</param>
			/// <param name="patientCode"> A <c>System.String</c> instance.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public void GetPatientCode(TransactionManager transactionManager, System.String locationCode, System.String lastName, ref System.String patientCode)
		{
			 GetPatientCode(transactionManager, 0, int.MaxValue , locationCode, lastName, ref patientCode);
		}
		
		/// <summary>
		///	This method wrap the '_Patient_GetPatientCode' stored procedure. 
		/// </summary>
		/// <param name="locationCode"> A <c>System.String</c> instance.</param>
		/// <param name="lastName"> A <c>System.String</c> instance.</param>
			/// <param name="patientCode"> A <c>System.String</c> instance.</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">Number of rows to return.</param>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <remark>This method is generate from a stored procedure.</remark>
		public abstract void GetPatientCode(TransactionManager transactionManager, int start, int pageLength , System.String locationCode, System.String lastName, ref System.String patientCode);
		
		#endregion
		
		#endregion

		#region Helper Functions	
		
		/// <summary>
		/// Fill a TList&lt;Patient&gt; From a DataReader.
		/// </summary>
		/// <param name="reader">Datareader</param>
		/// <param name="rows">The collection to fill</param>
		/// <param name="start">Row number at which to start reading, the first row is 0.</param>
		/// <param name="pageLength">number of rows.</param>
		/// <returns>a <see cref="TList&lt;Patient&gt;"/></returns>
		public static TList<Patient> Fill(IDataReader reader, TList<Patient> rows, int start, int pageLength)
		{
			NetTiersProvider currentProvider = DataRepository.Provider;
            bool useEntityFactory = currentProvider.UseEntityFactory;
            bool enableEntityTracking = currentProvider.EnableEntityTracking;
            LoadPolicy currentLoadPolicy = currentProvider.CurrentLoadPolicy;
			Type entityCreationFactoryType = currentProvider.EntityCreationalFactoryType;
			
			// advance to the starting row
			for (int i = 0; i < start; i++)
			{
				if (!reader.Read())
				return rows; // not enough rows, just return
			}
			for (int i = 0; i < pageLength; i++)
			{
				if (!reader.Read())
					break; // we are done
					
				string key = null;
				
				VCS.Entities.Patient c = null;
				if (useEntityFactory)
				{
					key = new System.Text.StringBuilder("Patient")
					.Append("|").Append((System.String)reader[((int)PatientColumn.PatientCode - 1)]).ToString();
					c = EntityManager.LocateOrCreate<Patient>(
					key.ToString(), // EntityTrackingKey
					"Patient",  //Creational Type
					entityCreationFactoryType,  //Factory used to create entity
					enableEntityTracking); // Track this entity?
				}
				else
				{
					c = new VCS.Entities.Patient();
				}
				
				if (!enableEntityTracking ||
					c.EntityState == EntityState.Added ||
					(enableEntityTracking &&
					
						(
							(currentLoadPolicy == LoadPolicy.PreserveChanges && c.EntityState == EntityState.Unchanged) ||
							(currentLoadPolicy == LoadPolicy.DiscardChanges && c.EntityState != EntityState.Unchanged)
						)
					))
				{
					c.SuppressEntityEvents = true;
					c.PatientCode = (System.String)reader[((int)PatientColumn.PatientCode - 1)];
					c.OriginalPatientCode = c.PatientCode;
					c.FirstName = (System.String)reader[((int)PatientColumn.FirstName - 1)];
					c.MiddleName = (reader.IsDBNull(((int)PatientColumn.MiddleName - 1)))?null:(System.String)reader[((int)PatientColumn.MiddleName - 1)];
					c.LastName = (System.String)reader[((int)PatientColumn.LastName - 1)];
					c.DateOfBirth = (System.DateTime)reader[((int)PatientColumn.DateOfBirth - 1)];
					c.Sex = (System.String)reader[((int)PatientColumn.Sex - 1)];
					c.MemberType = (System.String)reader[((int)PatientColumn.MemberType - 1)];
					c.MembershipSosNumber = (reader.IsDBNull(((int)PatientColumn.MembershipSosNumber - 1)))?null:(System.String)reader[((int)PatientColumn.MembershipSosNumber - 1)];
					c.MembershipSosExpDate = (reader.IsDBNull(((int)PatientColumn.MembershipSosExpDate - 1)))?null:(System.DateTime?)reader[((int)PatientColumn.MembershipSosExpDate - 1)];
					c.Nationality = (System.String)reader[((int)PatientColumn.Nationality - 1)];
					c.HomeStreet = (reader.IsDBNull(((int)PatientColumn.HomeStreet - 1)))?null:(System.String)reader[((int)PatientColumn.HomeStreet - 1)];
					c.HomeWard = (reader.IsDBNull(((int)PatientColumn.HomeWard - 1)))?null:(System.String)reader[((int)PatientColumn.HomeWard - 1)];
					c.HomeDistrict = (reader.IsDBNull(((int)PatientColumn.HomeDistrict - 1)))?null:(System.String)reader[((int)PatientColumn.HomeDistrict - 1)];
					c.HomeCity = (reader.IsDBNull(((int)PatientColumn.HomeCity - 1)))?null:(System.String)reader[((int)PatientColumn.HomeCity - 1)];
					c.HomeCountry = (reader.IsDBNull(((int)PatientColumn.HomeCountry - 1)))?null:(System.String)reader[((int)PatientColumn.HomeCountry - 1)];
					c.CompanyCode = (reader.IsDBNull(((int)PatientColumn.CompanyCode - 1)))?null:(System.String)reader[((int)PatientColumn.CompanyCode - 1)];
					c.BillingAddress = (reader.IsDBNull(((int)PatientColumn.BillingAddress - 1)))?null:(System.String)reader[((int)PatientColumn.BillingAddress - 1)];
					c.HomePhone = (reader.IsDBNull(((int)PatientColumn.HomePhone - 1)))?null:(System.String)reader[((int)PatientColumn.HomePhone - 1)];
					c.MobilePhone = (reader.IsDBNull(((int)PatientColumn.MobilePhone - 1)))?null:(System.String)reader[((int)PatientColumn.MobilePhone - 1)];
					c.CompanyPhone = (reader.IsDBNull(((int)PatientColumn.CompanyPhone - 1)))?null:(System.String)reader[((int)PatientColumn.CompanyPhone - 1)];
					c.Fax = (reader.IsDBNull(((int)PatientColumn.Fax - 1)))?null:(System.String)reader[((int)PatientColumn.Fax - 1)];
					c.EmailAddress = (reader.IsDBNull(((int)PatientColumn.EmailAddress - 1)))?null:(System.String)reader[((int)PatientColumn.EmailAddress - 1)];
					c.CreateUser = (reader.IsDBNull(((int)PatientColumn.CreateUser - 1)))?null:(System.String)reader[((int)PatientColumn.CreateUser - 1)];
					c.CreateDate = (System.DateTime)reader[((int)PatientColumn.CreateDate - 1)];
					c.ValidCorporate = (System.Boolean)reader[((int)PatientColumn.ValidCorporate - 1)];
					c.DefaultPaymentMode = (System.String)reader[((int)PatientColumn.DefaultPaymentMode - 1)];
					c.InsuranceCardNumber = (reader.IsDBNull(((int)PatientColumn.InsuranceCardNumber - 1)))?null:(System.String)reader[((int)PatientColumn.InsuranceCardNumber - 1)];
					c.InsuranceCardExpDate = (reader.IsDBNull(((int)PatientColumn.InsuranceCardExpDate - 1)))?null:(System.DateTime?)reader[((int)PatientColumn.InsuranceCardExpDate - 1)];
					c.IsDisabled = (System.Boolean)reader[((int)PatientColumn.IsDisabled - 1)];
					c.UpdateUser = (reader.IsDBNull(((int)PatientColumn.UpdateUser - 1)))?null:(System.String)reader[((int)PatientColumn.UpdateUser - 1)];
					c.UpdateDate = (System.DateTime)reader[((int)PatientColumn.UpdateDate - 1)];
					c.ApptRemark = (reader.IsDBNull(((int)PatientColumn.ApptRemark - 1)))?null:(System.String)reader[((int)PatientColumn.ApptRemark - 1)];
					c.Remark = (reader.IsDBNull(((int)PatientColumn.Remark - 1)))?null:(System.String)reader[((int)PatientColumn.Remark - 1)];
					c.EntityTrackingKey = key;
					c.AcceptChanges();
					c.SuppressEntityEvents = false;
				}
				rows.Add(c);
			}
		return rows;
		}		
		/// <summary>
		/// Refreshes the <see cref="VCS.Entities.Patient"/> object from the <see cref="IDataReader"/>.
		/// </summary>
		/// <param name="reader">The <see cref="IDataReader"/> to read from.</param>
		/// <param name="entity">The <see cref="VCS.Entities.Patient"/> object to refresh.</param>
		public static void RefreshEntity(IDataReader reader, VCS.Entities.Patient entity)
		{
			if (!reader.Read()) return;
			
			entity.PatientCode = (System.String)reader[((int)PatientColumn.PatientCode - 1)];
			entity.OriginalPatientCode = (System.String)reader["PatientCode"];
			entity.FirstName = (System.String)reader[((int)PatientColumn.FirstName - 1)];
			entity.MiddleName = (reader.IsDBNull(((int)PatientColumn.MiddleName - 1)))?null:(System.String)reader[((int)PatientColumn.MiddleName - 1)];
			entity.LastName = (System.String)reader[((int)PatientColumn.LastName - 1)];
			entity.DateOfBirth = (System.DateTime)reader[((int)PatientColumn.DateOfBirth - 1)];
			entity.Sex = (System.String)reader[((int)PatientColumn.Sex - 1)];
			entity.MemberType = (System.String)reader[((int)PatientColumn.MemberType - 1)];
			entity.MembershipSosNumber = (reader.IsDBNull(((int)PatientColumn.MembershipSosNumber - 1)))?null:(System.String)reader[((int)PatientColumn.MembershipSosNumber - 1)];
			entity.MembershipSosExpDate = (reader.IsDBNull(((int)PatientColumn.MembershipSosExpDate - 1)))?null:(System.DateTime?)reader[((int)PatientColumn.MembershipSosExpDate - 1)];
			entity.Nationality = (System.String)reader[((int)PatientColumn.Nationality - 1)];
			entity.HomeStreet = (reader.IsDBNull(((int)PatientColumn.HomeStreet - 1)))?null:(System.String)reader[((int)PatientColumn.HomeStreet - 1)];
			entity.HomeWard = (reader.IsDBNull(((int)PatientColumn.HomeWard - 1)))?null:(System.String)reader[((int)PatientColumn.HomeWard - 1)];
			entity.HomeDistrict = (reader.IsDBNull(((int)PatientColumn.HomeDistrict - 1)))?null:(System.String)reader[((int)PatientColumn.HomeDistrict - 1)];
			entity.HomeCity = (reader.IsDBNull(((int)PatientColumn.HomeCity - 1)))?null:(System.String)reader[((int)PatientColumn.HomeCity - 1)];
			entity.HomeCountry = (reader.IsDBNull(((int)PatientColumn.HomeCountry - 1)))?null:(System.String)reader[((int)PatientColumn.HomeCountry - 1)];
			entity.CompanyCode = (reader.IsDBNull(((int)PatientColumn.CompanyCode - 1)))?null:(System.String)reader[((int)PatientColumn.CompanyCode - 1)];
			entity.BillingAddress = (reader.IsDBNull(((int)PatientColumn.BillingAddress - 1)))?null:(System.String)reader[((int)PatientColumn.BillingAddress - 1)];
			entity.HomePhone = (reader.IsDBNull(((int)PatientColumn.HomePhone - 1)))?null:(System.String)reader[((int)PatientColumn.HomePhone - 1)];
			entity.MobilePhone = (reader.IsDBNull(((int)PatientColumn.MobilePhone - 1)))?null:(System.String)reader[((int)PatientColumn.MobilePhone - 1)];
			entity.CompanyPhone = (reader.IsDBNull(((int)PatientColumn.CompanyPhone - 1)))?null:(System.String)reader[((int)PatientColumn.CompanyPhone - 1)];
			entity.Fax = (reader.IsDBNull(((int)PatientColumn.Fax - 1)))?null:(System.String)reader[((int)PatientColumn.Fax - 1)];
			entity.EmailAddress = (reader.IsDBNull(((int)PatientColumn.EmailAddress - 1)))?null:(System.String)reader[((int)PatientColumn.EmailAddress - 1)];
			entity.CreateUser = (reader.IsDBNull(((int)PatientColumn.CreateUser - 1)))?null:(System.String)reader[((int)PatientColumn.CreateUser - 1)];
			entity.CreateDate = (System.DateTime)reader[((int)PatientColumn.CreateDate - 1)];
			entity.ValidCorporate = (System.Boolean)reader[((int)PatientColumn.ValidCorporate - 1)];
			entity.DefaultPaymentMode = (System.String)reader[((int)PatientColumn.DefaultPaymentMode - 1)];
			entity.InsuranceCardNumber = (reader.IsDBNull(((int)PatientColumn.InsuranceCardNumber - 1)))?null:(System.String)reader[((int)PatientColumn.InsuranceCardNumber - 1)];
			entity.InsuranceCardExpDate = (reader.IsDBNull(((int)PatientColumn.InsuranceCardExpDate - 1)))?null:(System.DateTime?)reader[((int)PatientColumn.InsuranceCardExpDate - 1)];
			entity.IsDisabled = (System.Boolean)reader[((int)PatientColumn.IsDisabled - 1)];
			entity.UpdateUser = (reader.IsDBNull(((int)PatientColumn.UpdateUser - 1)))?null:(System.String)reader[((int)PatientColumn.UpdateUser - 1)];
			entity.UpdateDate = (System.DateTime)reader[((int)PatientColumn.UpdateDate - 1)];
			entity.ApptRemark = (reader.IsDBNull(((int)PatientColumn.ApptRemark - 1)))?null:(System.String)reader[((int)PatientColumn.ApptRemark - 1)];
			entity.Remark = (reader.IsDBNull(((int)PatientColumn.Remark - 1)))?null:(System.String)reader[((int)PatientColumn.Remark - 1)];
			entity.AcceptChanges();
		}
		
		/// <summary>
		/// Refreshes the <see cref="VCS.Entities.Patient"/> object from the <see cref="DataSet"/>.
		/// </summary>
		/// <param name="dataSet">The <see cref="DataSet"/> to read from.</param>
		/// <param name="entity">The <see cref="VCS.Entities.Patient"/> object.</param>
		public static void RefreshEntity(DataSet dataSet, VCS.Entities.Patient entity)
		{
			DataRow dataRow = dataSet.Tables[0].Rows[0];
			
			entity.PatientCode = (System.String)dataRow["PatientCode"];
			entity.OriginalPatientCode = (System.String)dataRow["PatientCode"];
			entity.FirstName = (System.String)dataRow["FirstName"];
			entity.MiddleName = Convert.IsDBNull(dataRow["MiddleName"]) ? null : (System.String)dataRow["MiddleName"];
			entity.LastName = (System.String)dataRow["LastName"];
			entity.DateOfBirth = (System.DateTime)dataRow["DateOfBirth"];
			entity.Sex = (System.String)dataRow["Sex"];
			entity.MemberType = (System.String)dataRow["MemberType"];
			entity.MembershipSosNumber = Convert.IsDBNull(dataRow["MembershipSOSNumber"]) ? null : (System.String)dataRow["MembershipSOSNumber"];
			entity.MembershipSosExpDate = Convert.IsDBNull(dataRow["MembershipSOSExpDate"]) ? null : (System.DateTime?)dataRow["MembershipSOSExpDate"];
			entity.Nationality = (System.String)dataRow["Nationality"];
			entity.HomeStreet = Convert.IsDBNull(dataRow["HomeStreet"]) ? null : (System.String)dataRow["HomeStreet"];
			entity.HomeWard = Convert.IsDBNull(dataRow["HomeWard"]) ? null : (System.String)dataRow["HomeWard"];
			entity.HomeDistrict = Convert.IsDBNull(dataRow["HomeDistrict"]) ? null : (System.String)dataRow["HomeDistrict"];
			entity.HomeCity = Convert.IsDBNull(dataRow["HomeCity"]) ? null : (System.String)dataRow["HomeCity"];
			entity.HomeCountry = Convert.IsDBNull(dataRow["HomeCountry"]) ? null : (System.String)dataRow["HomeCountry"];
			entity.CompanyCode = Convert.IsDBNull(dataRow["CompanyCode"]) ? null : (System.String)dataRow["CompanyCode"];
			entity.BillingAddress = Convert.IsDBNull(dataRow["BillingAddress"]) ? null : (System.String)dataRow["BillingAddress"];
			entity.HomePhone = Convert.IsDBNull(dataRow["HomePhone"]) ? null : (System.String)dataRow["HomePhone"];
			entity.MobilePhone = Convert.IsDBNull(dataRow["MobilePhone"]) ? null : (System.String)dataRow["MobilePhone"];
			entity.CompanyPhone = Convert.IsDBNull(dataRow["CompanyPhone"]) ? null : (System.String)dataRow["CompanyPhone"];
			entity.Fax = Convert.IsDBNull(dataRow["Fax"]) ? null : (System.String)dataRow["Fax"];
			entity.EmailAddress = Convert.IsDBNull(dataRow["EmailAddress"]) ? null : (System.String)dataRow["EmailAddress"];
			entity.CreateUser = Convert.IsDBNull(dataRow["CreateUser"]) ? null : (System.String)dataRow["CreateUser"];
			entity.CreateDate = (System.DateTime)dataRow["CreateDate"];
			entity.ValidCorporate = (System.Boolean)dataRow["ValidCorporate"];
			entity.DefaultPaymentMode = (System.String)dataRow["DefaultPaymentMode"];
			entity.InsuranceCardNumber = Convert.IsDBNull(dataRow["InsuranceCardNumber"]) ? null : (System.String)dataRow["InsuranceCardNumber"];
			entity.InsuranceCardExpDate = Convert.IsDBNull(dataRow["InsuranceCardExpDate"]) ? null : (System.DateTime?)dataRow["InsuranceCardExpDate"];
			entity.IsDisabled = (System.Boolean)dataRow["IsDisabled"];
			entity.UpdateUser = Convert.IsDBNull(dataRow["UpdateUser"]) ? null : (System.String)dataRow["UpdateUser"];
			entity.UpdateDate = (System.DateTime)dataRow["UpdateDate"];
			entity.ApptRemark = Convert.IsDBNull(dataRow["ApptRemark"]) ? null : (System.String)dataRow["ApptRemark"];
			entity.Remark = Convert.IsDBNull(dataRow["Remark"]) ? null : (System.String)dataRow["Remark"];
			entity.AcceptChanges();
		}
		#endregion 
		
		#region DeepLoad Methods
		/// <summary>
		/// Deep Loads the <see cref="IEntity"/> object with criteria based of the child 
		/// property collections only N Levels Deep based on the <see cref="DeepLoadType"/>.
		/// </summary>
		/// <remarks>
		/// Use this method with caution as it is possible to DeepLoad with Recursion and traverse an entire object graph.
		/// </remarks>
		/// <param name="transactionManager"><see cref="TransactionManager"/> object</param>
		/// <param name="entity">The <see cref="VCS.Entities.Patient"/> object to load.</param>
		/// <param name="deep">Boolean. A flag that indicates whether to recursively save all Property Collection that are descendants of this instance. If True, saves the complete object graph below this object. If False, saves this object only. </param>
		/// <param name="deepLoadType">DeepLoadType Enumeration to Include/Exclude object property collections from Load.</param>
		/// <param name="childTypes">VCS.Entities.Patient Property Collection Type Array To Include or Exclude from Load</param>
		/// <param name="innerList">A collection of child types for easy access.</param>
	    /// <exception cref="ArgumentNullException">entity or childTypes is null.</exception>
	    /// <exception cref="ArgumentException">deepLoadType has invalid value.</exception>
		public override void DeepLoad(TransactionManager transactionManager, VCS.Entities.Patient entity, bool deep, DeepLoadType deepLoadType, System.Type[] childTypes, DeepSession innerList)
		{
			if(entity == null)
				return;

			#region CompanyCodeSource	
			if (CanDeepLoad(entity, "Company|CompanyCodeSource", deepLoadType, innerList) 
				&& entity.CompanyCodeSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.CompanyCode ?? string.Empty);
				Company tmpEntity = EntityManager.LocateEntity<Company>(EntityLocator.ConstructKeyFromPkItems(typeof(Company), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.CompanyCodeSource = tmpEntity;
				else
					entity.CompanyCodeSource = DataRepository.CompanyProvider.GetByCompanyCode(transactionManager, (entity.CompanyCode ?? string.Empty));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'CompanyCodeSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.CompanyCodeSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CompanyProvider.DeepLoad(transactionManager, entity.CompanyCodeSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion CompanyCodeSource

			#region NationalitySource	
			if (CanDeepLoad(entity, "Country|NationalitySource", deepLoadType, innerList) 
				&& entity.NationalitySource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.Nationality;
				Country tmpEntity = EntityManager.LocateEntity<Country>(EntityLocator.ConstructKeyFromPkItems(typeof(Country), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.NationalitySource = tmpEntity;
				else
					entity.NationalitySource = DataRepository.CountryProvider.GetByCitizenName(transactionManager, entity.Nationality);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'NationalitySource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.NationalitySource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CountryProvider.DeepLoad(transactionManager, entity.NationalitySource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion NationalitySource

			#region HomeCountrySource	
			if (CanDeepLoad(entity, "Country|HomeCountrySource", deepLoadType, innerList) 
				&& entity.HomeCountrySource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = (entity.HomeCountry ?? string.Empty);
				Country tmpEntity = EntityManager.LocateEntity<Country>(EntityLocator.ConstructKeyFromPkItems(typeof(Country), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.HomeCountrySource = tmpEntity;
				else
					entity.HomeCountrySource = DataRepository.CountryProvider.GetByCountryName(transactionManager, (entity.HomeCountry ?? string.Empty));		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'HomeCountrySource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.HomeCountrySource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.CountryProvider.DeepLoad(transactionManager, entity.HomeCountrySource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion HomeCountrySource

			#region MemberTypeSource	
			if (CanDeepLoad(entity, "MemberType|MemberTypeSource", deepLoadType, innerList) 
				&& entity.MemberTypeSource == null)
			{
				object[] pkItems = new object[1];
				pkItems[0] = entity.MemberType;
				MemberType tmpEntity = EntityManager.LocateEntity<MemberType>(EntityLocator.ConstructKeyFromPkItems(typeof(MemberType), pkItems), DataRepository.Provider.EnableEntityTracking);
				if (tmpEntity != null)
					entity.MemberTypeSource = tmpEntity;
				else
					entity.MemberTypeSource = DataRepository.MemberTypeProvider.GetByMemberType(transactionManager, entity.MemberType);		
				
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'MemberTypeSource' loaded. key " + entity.EntityTrackingKey);
				#endif 
				
				if (deep && entity.MemberTypeSource != null)
				{
					innerList.SkipChildren = true;
					DataRepository.MemberTypeProvider.DeepLoad(transactionManager, entity.MemberTypeSource, deep, deepLoadType, childTypes, innerList);
					innerList.SkipChildren = false;
				}
					
			}
			#endregion MemberTypeSource
			
			//used to hold DeepLoad method delegates and fire after all the local children have been loaded.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
			// Deep load child collections  - Call GetByPatientCode methods when available
			
			#region InvoiceCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<Invoice>|InvoiceCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'InvoiceCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.InvoiceCollection = DataRepository.InvoiceProvider.GetByPatientCode(transactionManager, entity.PatientCode);

				if (deep && entity.InvoiceCollection.Count > 0)
				{
					deepHandles.Add("InvoiceCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<Invoice>) DataRepository.InvoiceProvider.DeepLoad,
						new object[] { transactionManager, entity.InvoiceCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			#region PatientActivationCollection
			//Relationship Type One : Many
			if (CanDeepLoad(entity, "List<PatientActivation>|PatientActivationCollection", deepLoadType, innerList)) 
			{
				#if NETTIERS_DEBUG
				System.Diagnostics.Debug.WriteLine("- property 'PatientActivationCollection' loaded. key " + entity.EntityTrackingKey);
				#endif 

				entity.PatientActivationCollection = DataRepository.PatientActivationProvider.GetByPatientCode(transactionManager, entity.PatientCode);

				if (deep && entity.PatientActivationCollection.Count > 0)
				{
					deepHandles.Add("PatientActivationCollection",
						new KeyValuePair<Delegate, object>((DeepLoadHandle<PatientActivation>) DataRepository.PatientActivationProvider.DeepLoad,
						new object[] { transactionManager, entity.PatientActivationCollection, deep, deepLoadType, childTypes, innerList }
					));
				}
			}		
			#endregion 
			
			
			//Fire all DeepLoad Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			deepHandles = null;
		}
		
		#endregion 
		
		#region DeepSave Methods

		/// <summary>
		/// Deep Save the entire object graph of the VCS.Entities.Patient object with criteria based of the child 
		/// Type property array and DeepSaveType.
		/// </summary>
		/// <param name="transactionManager">The transaction manager.</param>
		/// <param name="entity">VCS.Entities.Patient instance</param>
		/// <param name="deepSaveType">DeepSaveType Enumeration to Include/Exclude object property collections from Save.</param>
		/// <param name="childTypes">VCS.Entities.Patient Property Collection Type Array To Include or Exclude from Save</param>
		/// <param name="innerList">A Hashtable of child types for easy access.</param>
		public override bool DeepSave(TransactionManager transactionManager, VCS.Entities.Patient entity, DeepSaveType deepSaveType, System.Type[] childTypes, DeepSession innerList)
		{	
			if (entity == null)
				return false;
							
			#region Composite Parent Properties
			//Save Source Composite Properties, however, don't call deep save on them.  
			//So they only get saved a single level deep.
			
			#region CompanyCodeSource
			if (CanDeepSave(entity, "Company|CompanyCodeSource", deepSaveType, innerList) 
				&& entity.CompanyCodeSource != null)
			{
				DataRepository.CompanyProvider.Save(transactionManager, entity.CompanyCodeSource);
				entity.CompanyCode = entity.CompanyCodeSource.CompanyCode;
			}
			#endregion 
			
			#region NationalitySource
			if (CanDeepSave(entity, "Country|NationalitySource", deepSaveType, innerList) 
				&& entity.NationalitySource != null)
			{
				DataRepository.CountryProvider.Save(transactionManager, entity.NationalitySource);
				entity.Nationality = entity.NationalitySource.CitizenName;
			}
			#endregion 
			
			#region HomeCountrySource
			if (CanDeepSave(entity, "Country|HomeCountrySource", deepSaveType, innerList) 
				&& entity.HomeCountrySource != null)
			{
				DataRepository.CountryProvider.Save(transactionManager, entity.HomeCountrySource);
				entity.HomeCountry = entity.HomeCountrySource.CountryName;
			}
			#endregion 
			
			#region MemberTypeSource
			if (CanDeepSave(entity, "MemberType|MemberTypeSource", deepSaveType, innerList) 
				&& entity.MemberTypeSource != null)
			{
				DataRepository.MemberTypeProvider.Save(transactionManager, entity.MemberTypeSource);
				entity.MemberType = entity.MemberTypeSource.MemberType;
			}
			#endregion 
			#endregion Composite Parent Properties

			// Save Root Entity through Provider
			if (!entity.IsDeleted)
				this.Save(transactionManager, entity);
			
			//used to hold DeepSave method delegates and fire after all the local children have been saved.
			Dictionary<string, KeyValuePair<Delegate, object>> deepHandles = new Dictionary<string, KeyValuePair<Delegate, object>>();
	
			#region List<Invoice>
				if (CanDeepSave(entity.InvoiceCollection, "List<Invoice>|InvoiceCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(Invoice child in entity.InvoiceCollection)
					{
						if(child.PatientCodeSource != null)
						{
							child.PatientCode = child.PatientCodeSource.PatientCode;
						}
						else
						{
							child.PatientCode = entity.PatientCode;
						}

					}

					if (entity.InvoiceCollection.Count > 0 || entity.InvoiceCollection.DeletedItems.Count > 0)
					{
						//DataRepository.InvoiceProvider.Save(transactionManager, entity.InvoiceCollection);
						
						deepHandles.Add("InvoiceCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< Invoice >) DataRepository.InvoiceProvider.DeepSave,
							new object[] { transactionManager, entity.InvoiceCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
	
			#region List<PatientActivation>
				if (CanDeepSave(entity.PatientActivationCollection, "List<PatientActivation>|PatientActivationCollection", deepSaveType, innerList)) 
				{	
					// update each child parent id with the real parent id (mostly used on insert)
					foreach(PatientActivation child in entity.PatientActivationCollection)
					{
						if(child.PatientCodeSource != null)
						{
							child.PatientCode = child.PatientCodeSource.PatientCode;
						}
						else
						{
							child.PatientCode = entity.PatientCode;
						}

					}

					if (entity.PatientActivationCollection.Count > 0 || entity.PatientActivationCollection.DeletedItems.Count > 0)
					{
						//DataRepository.PatientActivationProvider.Save(transactionManager, entity.PatientActivationCollection);
						
						deepHandles.Add("PatientActivationCollection",
						new KeyValuePair<Delegate, object>((DeepSaveHandle< PatientActivation >) DataRepository.PatientActivationProvider.DeepSave,
							new object[] { transactionManager, entity.PatientActivationCollection, deepSaveType, childTypes, innerList }
						));
					}
				} 
			#endregion 
				
			//Fire all DeepSave Items
			foreach(KeyValuePair<Delegate, object> pair in deepHandles.Values)
		    {
                pair.Key.DynamicInvoke((object[])pair.Value);
		    }
			
			// Save Root Entity through Provider, if not already saved in delete mode
			if (entity.IsDeleted)
				this.Save(transactionManager, entity);
				

			deepHandles = null;
						
			return true;
		}
		#endregion
	} // end class
	
	#region PatientChildEntityTypes
	
	///<summary>
	/// Enumeration used to expose the different child entity types 
	/// for child properties in <c>VCS.Entities.Patient</c>
	///</summary>
	public enum PatientChildEntityTypes
	{
		
		///<summary>
		/// Composite Property for <c>Company</c> at CompanyCodeSource
		///</summary>
		[ChildEntityType(typeof(Company))]
		Company,
			
		///<summary>
		/// Composite Property for <c>Country</c> at NationalitySource
		///</summary>
		[ChildEntityType(typeof(Country))]
		Country,
			
		///<summary>
		/// Composite Property for <c>MemberType</c> at MemberTypeSource
		///</summary>
		[ChildEntityType(typeof(MemberType))]
		MemberType,
	
		///<summary>
		/// Collection of <c>Patient</c> as OneToMany for InvoiceCollection
		///</summary>
		[ChildEntityType(typeof(TList<Invoice>))]
		InvoiceCollection,

		///<summary>
		/// Collection of <c>Patient</c> as OneToMany for PatientActivationCollection
		///</summary>
		[ChildEntityType(typeof(TList<PatientActivation>))]
		PatientActivationCollection,
	}
	
	#endregion PatientChildEntityTypes
	
	#region PatientFilterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="SqlFilterBuilder&lt;PatientColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Patient"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PatientFilterBuilder : SqlFilterBuilder<PatientColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatientFilterBuilder class.
		/// </summary>
		public PatientFilterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PatientFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PatientFilterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PatientFilterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PatientFilterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PatientFilterBuilder
	
	#region PatientParameterBuilder
	
	/// <summary>
	/// A strongly-typed instance of the <see cref="ParameterizedSqlFilterBuilder&lt;PatientColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Patient"/> object.
	/// </summary>
	[CLSCompliant(true)]
	public class PatientParameterBuilder : ParameterizedSqlFilterBuilder<PatientColumn>
	{
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatientParameterBuilder class.
		/// </summary>
		public PatientParameterBuilder() : base() { }

		/// <summary>
		/// Initializes a new instance of the PatientParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		public PatientParameterBuilder(bool ignoreCase) : base(ignoreCase) { }

		/// <summary>
		/// Initializes a new instance of the PatientParameterBuilder class.
		/// </summary>
		/// <param name="ignoreCase">Specifies whether to create case-insensitive statements.</param>
		/// <param name="useAnd">Specifies whether to combine statements using AND or OR.</param>
		public PatientParameterBuilder(bool ignoreCase, bool useAnd) : base(ignoreCase, useAnd) { }

		#endregion Constructors
	}

	#endregion PatientParameterBuilder
	
	#region PatientSortBuilder
    
    /// <summary>
    /// A strongly-typed instance of the <see cref="SqlSortBuilder&lt;PatientColumn&gt;"/> class
	/// that is used exclusively with a <see cref="Patient"/> object.
    /// </summary>
    [CLSCompliant(true)]
    public class PatientSortBuilder : SqlSortBuilder<PatientColumn>
    {
		#region Constructors

		/// <summary>
		/// Initializes a new instance of the PatientSqlSortBuilder class.
		/// </summary>
		public PatientSortBuilder() : base() { }

		#endregion Constructors

    }    
    #endregion PatientSortBuilder
	
} // end namespace
